/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;
import DTO.CFields;
import DTO.CMenu;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class CMenuDAO extends IData<CMenu>{

    @Override
    public CMenu add(CMenu item) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected void add(CMenu item, int t) {
        try {
            ps.setBoolean(1, item.getShow());
            ps.setInt(2, item.getMenuId());
            ps.setInt(3, item.getGroupId());
            ps.addBatch();
        } catch (SQLException ex) {
            Logger.getLogger(CMenuDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void saveBatch() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int addrows(List<CMenu> list, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public CMenu Find(CMenu item, List<CMenu> list) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected Object OnSubmit(CMenu item, int t, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Object insertOnSubmit(CMenu item, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Object updateOnSubmint(CMenu item, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Object deleteOnSubmint(CMenu item, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected CMenu getItem(ResultSet rs) {
        CMenu item = new CMenu();
        try {
            item.setGroupId(rs.getInt(CFields.group_id));
            item.setLevel(rs.getInt("level"));
            item.setOrder(rs.getInt("order"));
            item.setShow(rs.getBoolean("show"));
            item.setTitle(rs.getString("title"));
            item.setMenuId(rs.getInt("menu_id"));
        } catch (SQLException ex) {
            Logger.getLogger(CMenuDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return item;
    }

    @Override
    public List<CMenu> getAll(SubConfig config) {
        String mysql =" select * from vmenu " + this.sWhere;
        return this.getAll(mysql, config);
    }
    
    public void updates(List<CMenu> items,SubConfig config){
        try {
            this.query ="update items set show =? where menu_id=? and group_id=?";
            this.updateRows(items, config);
        } catch (SQLException ex) {
            Logger.getLogger(CMenuDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
